/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn;

import cn.webrx.config.AppConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * <p>Project: spring2022 - Demo
 * <p>Powered by webrx On 2022-03-16 16:49:59
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Demo {
    public static void main(String[] args) throws SQLException {
        var c = new AnnotationConfigApplicationContext(AppConfig.class);
        //
        Connection conn = c.getBean(DataSource.class).getConnection();
        System.out.println(conn);


        System.out.println(c.getBeanDefinitionCount());

        for (String n : c.getBeanDefinitionNames()) {
            System.out.println(n);
        }

        var d1 = c.getBean("md");
        var d2 = c.getBean("md");

        System.out.println(d1);
        System.out.println(d1 == d2);

        if(c.containsBeanDefinition("ud")) {
            var d3 = c.getBean("ud");
            var d4 = c.getBean("ud");
            System.out.println(d3);
            System.out.println(d3 == d4);
        }else if(c.containsBean("userdate")){
            var d3 = c.getBean("userdate");
            var d4 = c.getBean("userdate");
            System.out.println(d3);
            System.out.println(d3 == d4);
        }
    }
}
